﻿using Lhz.InternetService;
using Lhz.Serialization;

namespace Lhz.Test.Common
{
    public class ServiceCrudTester<TPk, TEntity> : CrudTester<TPk, TEntity> where TEntity : class
    {
        private string url;
        private ServiceInvoker wsi = new ServiceInvoker();
        private JsonSerializer js = new JsonSerializer();

        public ServiceCrudTester(string url)
        {
            this.url = url;
        }

        protected override TEntity QueryByPk(TPk pk, params string[] paths)
        {
            return js.Deserialize<TEntity>(js.Serialize(wsi.Invoke(url, "QueryByPk", pk, paths)));
        }

        protected override void Add(TEntity entity)
        {
            wsi.Invoke(url, "Add", entity);
        }

        protected override void Update(TEntity entity)
        {
            wsi.Invoke(url, "Update", entity);
        }

        protected override void Delete(TEntity entity)
        {
            wsi.Invoke(url, "Delete", entity);
        }
    }
}
